package com.brainhealth.web.controller.customer;

import com.brainhealth.common.annotation.Anonymous;
import com.brainhealth.common.core.controller.BaseController;
import com.brainhealth.common.core.domain.AjaxResult;
import com.brainhealth.customer.domain.vo.FirstCategoryPropertyVO;
import com.brainhealth.customer.service.IWarehouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * 我的货仓
 *
 * @author wll
 */
@RequestMapping("/warehouse/v1/")
@RestController
public class WarehouseController extends BaseController {

    @Autowired
    IWarehouseService warehouseService;

    @Anonymous
    @GetMapping("/get_property_list")
    public AjaxResult getPropertyList(HttpServletRequest request) {
        List<FirstCategoryPropertyVO> propertyList = warehouseService.getPropertyList(request);
        if (null == propertyList) {
            return error("查询我的货仓异常");
        }
        return success(propertyList);
    }

    @Anonymous
    @GetMapping("/get_used_property_list")
    public AjaxResult getPropertyVOList(HttpServletRequest request) {
        List<FirstCategoryPropertyVO> propertyList = warehouseService.getUsedPropertyList(request);
        if (null == propertyList) {
            return error("查询我的装饰异常");
        }
        return success(propertyList);
    }

    @Anonymous
    @PostMapping("/use_property")
    public AjaxResult useProperty(HttpServletRequest request, @RequestBody Map<String,String> map) {
        String propertyId = map.get("propertyId");
        Integer result = warehouseService.useProperty(request, propertyId);
        if (null == result) {
            return error("装饰房间异常");
        }
        return success(result);
    }

    @Anonymous
    @GetMapping("/is_use_property")
    public AjaxResult isUseProperty(HttpServletRequest request) {
        Integer result = warehouseService.isUseProperty(request);
        if (null == result) {
            return error("是否装饰过房间异常");
        }
        return success(result);
    }

    @Anonymous
    @PostMapping("/reset_property")
    public AjaxResult resetProperty(HttpServletRequest request) {
        Integer result = warehouseService.resetProperty(request);
        if (null == result) {
            return error("重新布置异常");
        }
        return success(result);
    }

}
